package cn.yangliu.nacos.comm.config.security.handler;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.yangliu.nacos.comm.enums.GlobalResultCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

/**
 * The interface Security authentication failure handler.
 *
 * @author 问道于盲
 */
public class SecurityAuthenticationFailureHandler
        implements AuthenticationFailureHandler, SecurityHandler {

    /**
     * current class's static member
     * The constant LOGGER.
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(SecurityAuthenticationFailureHandler.class);


    /**
     * On authentication failure.
     *
     * @param request   the request
     * @param response  the response
     * @param exception the exception
     * @throws IOException      the io exception
     * @throws ServletException the servlet exception
     */
    @Override
    public void onAuthenticationFailure(HttpServletRequest request,
                                        HttpServletResponse response, AuthenticationException exception)
            throws IOException, ServletException {
        handle(request, response, HttpStatus.UNAUTHORIZED, GlobalResultCode.ACCESS_DEFINE);

    }

}
